package com.cn.yugan.Utils;

import java.io.File;

/**
 * Created by Rover on 2017/1/6 .
 * Email 357319517@qq.com
 */
public class DelectFileUtils {
    /**
     * 删除文件
     *
     * @param file
     */
    public static void deleteFile(File file) {
        if (file.isFile()) {
            file.delete();
            return;
        }
    }

    /**
     * 删除文件夹
     *
     * @param file
     */
    public static void delectDir(File file) {
        if (file.isDirectory()) {
            File[] childFiles = file.listFiles();
            if (childFiles == null || childFiles.length == 0) {
                file.delete();
                return;
            }

            for (int i = 0; i < childFiles.length; i++) {
                deleteFile(childFiles[i]);
            }
            file.delete();
        }
    }

    /**
     * 清空文件夹
     *
     * @param file
     */
    public static void delectInnerDir(File file) {
        if (file.isDirectory()) {
            File[] childFiles = file.listFiles();
            if (childFiles == null || childFiles.length == 0) {
                return;
            }
            for (int i = 0; i < childFiles.length; i++) {
                deleteFile(childFiles[i]);
            }
        }
    }

}
